class InputsController < ApplicationController
  # GET /input
  # GET /input.xml
  def index
    @inputs = Input.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @input }
    end
  end

  # GET /input/1
  # GET /input/1.xml
  def show
    @input = Input.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @input }
    end
  end

  # GET /input/new
  # GET /input/new.xml
  def new
    @input = Input.new
    render :layout => false
  end

  # GET /input/1/edit
  def edit
    @input = Input.find(params[:id])
  end

  # POST /input
  # POST /input.xml
  def create
    @input = Input.new(params[:input])
    #@input.file_name = params[:input][:file_name].name
    #raise params[:input][:file_name].path
    if @input.save
      flash[:notice] = 'input was successfully created.'
      server = XMLRPC::Client.new("localhost", "/", 1234)
      server.call("ServiceEngine.loadModule", "#{@input.class_name}", "/var/www/public/uploads/modules/input/#{@input.code_file_name}")
      redirect_to(developers_path)
    else
      render :action => "new"
    end

  end

  # PUT /input/1
  # PUT /input/1.xml
  def update
    @input = Input.find(params[:id])

    respond_to do |format|
      if @input.update_attributes(params[:input])
        flash[:notice] = 'input was successfully updated.'
        redirect_to(developers_path)
      else
        render :action => "edit"
      end
    end
  end

  # DELETE /input/1
  # DELETE /input/1.xml
  def destroy
    @input = Input.find(params[:id])
    @input.destroy

    redirect_to(inputs_path)
  end


  def configure
    @input = Input.find(params[:id])
    @output = Output.find(params[:output])
    @options_html = @input.options_html
    @user_module = UserModule.find(params[:module]) if params[:module]
    if @user_module.nil?
      @user_module = UserModule.new
    end
  end

end
